package cn.webrx.config;

import cn.webrx.entity.Teacher;
import cn.webrx.entity.User;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

@Configuration("ccc")
@ComponentScan("cn.webrx.entity")
@Import(DruidConfig.class)
@PropertySource("t.properties")
public class AppConfig {

    @Bean(initMethod = "start",destroyMethod = "end") @Scope("singleton")
    public Teacher t1(){
        Teacher t = new Teacher(10,"周老师");
        System.out.println(t);
        return t;
    }

    @Bean("t2") @Scope("prototype")
    public Teacher t2(){
        Teacher t = new Teacher(22,"李老师");
        return t;
    }

    @Bean("t3") @Scope("prototype")
    public Teacher t2(@Value("88") int id, @Value("王老师") String name){
        Teacher t = new Teacher(id,name);
        return t;
    }

    @Bean @Scope("prototype")
    public User user(){
        User u = new User();
        u.setId(11);
        u.setName("李六");
        return u;
    }

    @Bean("u1") @Scope("prototype")
    public User user2(){
        User u = new User();
        u.setId(22);
        u.setName("李七");
        return u;
    }



    @Bean("t4") @Scope("prototype")
    public Teacher t2(@Value("88") int id, @Value("王老师") String name,@Value("#{'a,b,c,c,c,c,f'.split(',')}") String[] books,@Qualifier("u1") User user){
        Teacher t = new Teacher(id,name);
        t.setBooks(books);
        t.setUser(user);
        return t;
    }

}
